<template>
  <div class="comment-reply">
    <van-nav-bar
      :title="comment.reply_count ? `${comment.reply_count}条评论` : '暂无回复'"
    >
      <van-icon slot="left" name="cross" @click="$emit('close')" />
    </van-nav-bar>

    <div class="scroll-wrap">
      <!-- 当前评论项 -->
      <CommentItem :comment="comment" />
      <!-- /当前评论项 -->

      <!-- 评论回复列表 -->
      <van-cell title="全部回复"></van-cell>
      <CommentList :list="commentList" :source="comment.com_id" type="c" />
      <!-- /评论回复列表 -->
    </div>
    <!-- 底部区域 -->
    <div class="post-wrap">
      <van-button
        @click="isPostShow = true"
        class="post-btn"
        size="small"
        round=""
        >写评论</van-button
      >
    </div>
    <!-- /底部区域 -->

    <!-- 发布评论 -->
    <van-popup v-model="isPostShow" position="bottom">
      <CommentPost :target="comment.com_id" @post-success="onPostSuccess" />
    </van-popup>
    <!-- /发布评论 -->
  </div>
</template>

<script>
import CommentItem from "./comment-item.vue";
import CommentList from "./article-comment.vue";
import CommentPost from "./comment-post.vue";
export default {
  name: "CommentReply",
  components: {
    CommentItem,
    CommentList,
    CommentPost,
  },
  props: {
    comment: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      isPostShow: false,
      commentList: [],
    };
  },
  methods: {
    onPostSuccess(data) {
      // console.log(111);
      this.comment.reply_count++;
      this.isPostShow = false;
      this.commentList.unshift(data.new_obj);
    },
  },
};
</script>

<style scoped lang="less">
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  // 滚动
  overflow-y: auto;
}
.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  border: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}
</style>
